<template>
    <el-row type="flex" class="warp-bottom" justify="center" align="middle">
        <el-card class="box-card sign-warp">
            <div slot="header" class="clearfix">
                <span style="line-height: 36px;">注册</span>
            </div>
            <el-form :model="registerForm" :rules="rules" ref="registerForm" label-width="100px" class="demo-registerForm">
                <el-form-item label="用户名" prop="username">
                    <el-input v-model="registerForm.username"></el-input>
                </el-form-item>
                <el-form-item label="邮箱" prop="email">
                    <el-input v-model="registerForm.email"></el-input>
                </el-form-item>
                <el-form-item label="密码" prop="password">
                    <el-input v-model="registerForm.password"></el-input>
                </el-form-item>
                <el-form-item label="确认密码" prop="repassword">
                    <el-input v-model="registerForm.repassword"></el-input>
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" @click="handleSubmit">注册</el-button>
                    <el-button @click="handleReset">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
    </el-row>

</template>
<style>

</style>
<script>
     export default {
    data() {
      return {
        registerForm: {
          username: '',
          email: '',
          password: '',
          repassword: ''
        },
        rules: {
          username: [
            { required: true, message: '请输入用户名', trigger: 'blur' },
            { min: 5, max: 12, message: '长度在 5 到 12 个字符', trigger: 'change' }
          ],
          email: [
            { required: true, message: '请输入邮箱地址', trigger: 'blur' },
            { type: 'email', message: '请填写正确的邮箱地址', trigger: 'change' }
          ],
          password: [
            { required: true, message: '请输入密码', trigger: 'blur' },
            { min: 8, message: '密码最少8个字符', trigger: 'change' }
          ],
          repassword: [
            { required: true, message: '请输入密码', trigger: 'blur' },
            { min: 8, message: '密码最少8个字符', trigger: 'change' }
          ]
        }
      };
    },
    methods: {
      handleReset() {
        this.$refs.registerForm.resetFields();
      },
      handleSubmit(ev) {
        this.$refs.registerForm.validate((valid) => {
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      }
    }
  }
</script>
